var ctx;
var cellId;
var regionId;
var house ;
var unitId ;
var houseId ;
var total;
var selectCellId;
var selectRegionId;
var selectBuildingId;
var selectUnitId;
var selectHouseId;
var now = new Date();

function setCtx(ctx){
	this.ctx = ctx;
}
var scope = {};
/**
 * 程序入口
 */
//$(function() {
//	init();
//});


//验证缴费月数不为空
function checkMonths() {
	
	var months = $("#months").val();
	var reg=new RegExp("^[0-9]*$");
	
	//解决ie9以下placeholder与value重复的问题
	if(months == $("#months").attr("placeholder")){
		months = "";
	}
	
	if(months == null || months == "" || (!reg.test(months))){
		layer.tips('请填写月数!', '#months', {
			tips: 3,
			time:1000
		});
		return false;
	}else{
		return true;
	}
	
}

function init() {
	
	houseId = $('#houseId').val();
	var months = $('#months').val();
	console.info(houseId);
	if(checkMonths()){
		$.ajax({
	        type : "GET",
	        url : ctx + "/propertyBill/getHousePropertyInfo",
	        cache : false,
	        dataType : 'json',
	        data : {
	        	houseId :houseId,
	        	months:months
	        },
	        success : function(data) {
	        	console.info(data);
	        	if (data.success) {
	        		$("#houseArea").text(data.obj.area + "平米");
	        		$("#propertyBill").text(data.obj.perPrice + "元/平米/月");
	        		$("#payMoneyArea").text(data.obj.startDate + "——" + data.obj.endDate);
	        		
	        	}
	        }
		});
	}
	
}

//保存我要缴费账单
function saveManagementBill(){
	houseId = $('#houseId').val();
	var months = $('#months').val();
	var billTitle = $('#billTitle').val();
	
	if (checkMonths()) {
		var index = layer.load(1);
		$.post(ctx +"/propertyBill/saveManagementBill", {houseId:houseId , months:months, billTitle:billTitle}, function(data) {
			data = JSON.parse(data);
			if (data.success) {
				layer.open({
					type: 2,
					title: '物业费',
					content: ctx + "/propertyBill/payFeeBill?billId=" + data.obj,
					skin: "house-add",
					area: ["600px","480px"],
					end: function(){
						 layer.close(index);
					}
				});
//				layer.msg("操作成功", {
//					icon : 1,
//					skin : 'infobox',
//					time : 1000
//				// 2秒关闭（如果不配置，默认是3秒）
//				}, function() {
//					parent.window.location.href= ctx + "/propertyBill/getMyBill";
//					parent.layer.close(index); // 根据窗口索引关闭窗口
//					
//				});
			} else {
				layer.msg(data.msg, {
					icon : 2,
					time : 1000
				// 2秒关闭（如果不配置，默认是3秒）
				}, function() {
					 layer.close(index);
					parent.layer.close(index); // 根据窗口索引关闭窗口
				});
			}
		});
	}
	
} 